package com.example.zhunongzonghe.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.zhunongzonghe.beans.ZnMoresBean;
import com.example.zhunongzonghe.dao.ZnMoresMapper;
import com.example.zhunongzonghe.entity.ZnMores;
import com.example.zhunongzonghe.service.IZnMoresService;
import com.example.zhunongzonghe.utils.BeanCopyUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


@Service
public class ZnMoresServiceImpl extends ServiceImpl<ZnMoresMapper, ZnMores> implements IZnMoresService {
    @Autowired
    ZnMoresMapper znMoresMapper;
    @Override
    public Page<ZnMoresBean> SearchMoresAll(Integer currentPage, Integer pageNum, Object searchInfo) {
        Page<ZnMores> page = new Page<>(currentPage,pageNum);
        LambdaQueryWrapper<ZnMores> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.like(ZnMores::getMoresName,searchInfo)
                .or().like(ZnMores::getDistrict,searchInfo)
                .or().like(ZnMores::getMoresIntroduce,searchInfo);
        Page<ZnMores> moresPage = znMoresMapper.selectPage(page,queryWrapper);
        Page<ZnMoresBean> beanPage = BeanCopyUtils.copyBeanPage(moresPage,ZnMoresBean.class);
        return beanPage;
    }

    @Override
    public Page<ZnMoresBean> selectMoresAll(Integer currentPage, Integer pageNum) {
        Page<ZnMores> page = new Page<>(currentPage,pageNum);
        Page<ZnMores> znMoresPage = znMoresMapper.selectPage(page,null);
        Page<ZnMoresBean> beanPage = BeanCopyUtils.copyBeanPage(znMoresPage,ZnMoresBean.class);
        return beanPage;
    }

    @Override
    public ZnMoresBean getMoresInfo(Integer moresId) {
//        LambdaQueryWrapper<ZnMores> queryWrapper = new LambdaQueryWrapper<>();
//        queryWrapper.eq(ZnMores::getMoresId,moresId);
        ZnMores znMores = znMoresMapper.selectById(moresId);
        ZnMoresBean znMoresBean = BeanCopyUtils.copyBean(znMores,ZnMoresBean.class);
        return znMoresBean;
    }

    @Override
    public Page<ZnMoresBean> selectClassifyId(Integer currentPage,Integer pageSize,Integer classifyId) {
        Page<ZnMores> page = new Page<>(currentPage,pageSize);
        LambdaQueryWrapper<ZnMores> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ZnMores::getClassifyId,classifyId);
        Page<ZnMores> moresPage = znMoresMapper.selectPage(page,queryWrapper);
        Page<ZnMoresBean> beanPage = BeanCopyUtils.copyBeanPage(moresPage,ZnMoresBean.class);
        return beanPage;
    }
}
